﻿@model ProductModel.ProductAttributeValueListModel

@{
    //page title
    ViewBag.Title = string.Format(T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.EditAttributeDetails").Text, Model.ProductAttributeName, Model.ProductName);
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Products");
}

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "productattribute-form" }))
{
    @Html.AntiForgeryToken()
    <div class="content-header clearfix">
        <h1 class="pull-left">
            @string.Format(T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.EditAttributeDetails").Text, Model.ProductAttributeName, Model.ProductName)
            <small><i class="fa fa-arrow-circle-left"></i>@Html.ActionLink(T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.BackToProduct").Text, "Edit", "Product", new {Id = Model.ProductId}, null)</small>
        </h1>
        <div class="pull-right">
            &nbsp;
        </div>
    </div>

    <div class="content">
        <div class="panel-group">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div id="productattributevalues-grid"></div>

                    <script>
                        $(document).ready(function () {
                            $("#productattributevalues-grid").kendoGrid({
                                dataSource: {
                                    type: "json",
                                    transport: {
                                        read: {
                                            url: "@Html.Raw(Url.Action("ProductAttributeValueList", "Product", new { productAttributeMappingId = Model.ProductAttributeMappingId }))",
                                            type: "POST",
                                            dataType: "json",
                                            data: addAntiForgeryToken
                                        },
                                        destroy: {
                                            url: "@Html.Raw(Url.Action("ProductAttributeValueDelete", "Product"))",
                                            type: "POST",
                                            dataType: "json",
                                            data: addAntiForgeryToken
                                        }
                                    },
                                    schema: {
                                        data: "Data",
                                        total: "Total",
                                        errors: "Errors",
                                        model: {
                                            id: "Id",
                                            fields: {
                                                Product2Name: { editable: false, type: "string" },
                                                ProductId2: { editable: false, type: "number" }
                                            }
                                        }
                                    },
                                    error: function (e) {
                                        display_kendoui_grid_error(e);
                                        // Cancel the changes
                                        this.cancelChanges();
                                    },
                                    serverPaging: true,
                                    serverFiltering: true,
                                    serverSorting: true
                                },
                                pageable: {
                                    refresh: true,
                                    numeric: false,
                                    previousNext: false,
                                    info: false
                                },
                                editable: {
                                    confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                    mode: "inline"
                                },
                                scrollable: false,
                                columns: [
                                    {
                                        field: "AttributeValueTypeName",
                                        title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.Fields.AttributeValueType")",
                                        width: 200
                                    }, {
                                        field: "Name",
                                        title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.Fields.Name")",
                                        width: 200
                                    }, {
                                        field: "AssociatedProductName",
                                        title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.Fields.AssociatedProduct")",
                                        width: 200
                                    }, {
                                        field: "PriceAdjustmentStr",
                                        title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.Fields.PriceAdjustment")",
                                        width: 150
                                    }, {
                                        field: "WeightAdjustmentStr",
                                        title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.Fields.WeightAdjustment")",
                                        width: 150
                                    }, {
                                        field: "IsPreSelected",
                                        title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.Fields.IsPreSelected")",
                                        width: 150,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                        template: '# if(IsPreSelected) {# <i class="fa fa-check true-icon"></i> #} else {# <i class="fa fa-close false-icon"></i> #} #'
                                    }, {
                                        field: "PictureThumbnailUrl",
                                        title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.Fields.Picture")",
                                        template: '<img src="#=PictureThumbnailUrl#" />',
                                        width: 200
                                    }, {
                                        field: "DisplayOrder",
                                        title: "@T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.Fields.DisplayOrder")",
                                        width: 150
                                    }, {
                                        field: "Id",
                                        title: "@T("Admin.Common.Edit")",
                                        width: 100,
                                        template: "<input type='submit' value='@T("Admin.Common.Edit")' onclick=\"javascript:OpenWindow('@Url.Content("~/Admin/Product/ProductAttributeValueEditPopup/")#=Id#?btnId=btnRefresh&formId=productattribute-form', 800, 750, true); return false;\" class='btn btn-default' />"
                                    }, {
                                        command: { name: "destroy", text: "@T("Admin.Common.Delete")" },
                                        title: "@T("Admin.Common.Delete")",
                                        width: 200
                                    }
                                ]
                            });
                        });
                    </script>
                </div>
                <div class="panel-footer">
                    <button type="submit" id="btnAddNewValue" onclick="javascript:OpenWindow('@(Url.Action("ProductAttributeValueCreatePopup", "Product", new {productAttributeMappingId = Model.ProductAttributeMappingId, btnId = "btnRefresh", formId = "productattribute-form"}))', 800, 750, true); return false;" class="btn btn-primary">
                        @T("Admin.Catalog.Products.ProductAttributes.Attributes.Values.AddNew")
                    </button>
                    <input type="submit" id="btnRefresh" style="display: none" />
                    <script type="text/javascript">
                        $(document).ready(function () {
                            $('#btnRefresh').click(function () {
                                //refresh grid
                                var grid = $("#productattributevalues-grid").data('kendoGrid');
                                grid.dataSource.read();

                                //return false to don't reload a page
                                return false;
                            });
                        });
                    </script>
                </div>
            </div>
        </div>
    </div>
}
